<?php

function getTotalNum(DBC $db, $tablename, $keyword) {
    $total_num_product = 0;
    if ($keyword != "") {
        $sql = "SELECT COUNT(id) AS total FROM " . $tablename . " WHERE (code LIKE '%" . $keyword . "%' OR name LIKE '%" . $keyword . "%')";
    } else {
        $sql = "SELECT COUNT(id) AS total FROM " . $tablename;
    }
    $total_num = $db->fetchData($sql);
    if ($total_num != null && count($total_num) > 0) {
        $total_num_product = $total_num[0]['total'];
    }
    return $total_num_product;
}

function getGameByTitlePacket(DBC $db, $tablename, $keyword, $order, $begin, $page_size) {
    if ($keyword != "") {
        $sql = "SELECT * FROM " . $tablename . " WHERE (code LIKE '%" . $keyword . "%' OR name LIKE '%" . $keyword . "%') ORDER BY code LIMIT " . $begin . "," . $page_size;
    } else {
        $sql = "SELECT * FROM " . $tablename . " ORDER BY code LIMIT " . $begin . "," . $page_size;
    }
    if ($order == "status") {
        $sql = "SELECT * FROM " . $tablename . " ORDER BY status LIMIT " . $begin . "," . $page_size;
    }
    return $db->fetchData($sql);
}

?>
